//
//  HNThreeGoodNewEvaCell.m
//  优学荟管理系统
//
//  Created by edz on 2017/12/19.
//  Copyright © 2017年 星道三好. All rights reserved.
//

#import "HNThreeGoodNewEvaCell.h"

@implementation HNThreeGoodNewEvaCell
{
    __weak IBOutlet UIImageView *_Img;
    __weak IBOutlet UIButton *_State;
    __weak IBOutlet UIButton *_Select;
    __weak IBOutlet UILabel *_Title;
    __weak IBOutlet UILabel *_EvaCount;
    __weak IBOutlet UILabel *_TodayEvaCount;
}


- (void)setModel:(HNThreeGoodEvaNewModel *)Model {
    
    _Model = Model;
    
    // 头像
    [_Img sd_setImageWithURL:[NSURL URLWithString:[Model.avatar isKindOfClass:[NSNull class]] ? @"":Model.avatar] placeholderImage:[UIImage imageNamed:@"bg_picture_defaultbg_daoke_student_sign"]];
    // 名称
    _Title.text = Model.O_petName;
    // 是否显示未完成
    _State.hidden = [Model.type isEqualToNumber:@0] ? YES:NO;
    // 是否显示选中框 1未评价 2已评价
    _Select.hidden = [Model.commentCount integerValue] >= [Model.courseCount integerValue] ? YES:NO;
    // 是否选中
    _Select.selected = Model.Selected;
    // 禁止点击
    _Select.enabled = Model.Enable;
    // 总评价
    _EvaCount.text = [NSString stringWithFormat:@"%@/%@", Model.commentCount, Model.courseCount];
    // 今日有没有评价
    _TodayEvaCount.text = [NSString stringWithFormat:@"今日评价%@次", Model.todayCommentCount];
    
    /// 添加长按删除
    UILongPressGestureRecognizer * longPressGesture =[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(cellLongPress:)];
    longPressGesture.minimumPressDuration = 1.0f;//设置长按 时间
    [self addGestureRecognizer:longPressGesture];
}

- (IBAction)ClickSelect:(UIButton *)sender {
    
    self.ClickSelect ? self.ClickSelect(self.Model) : nil;
}

#pragma mark - 长按手势触发
- (void)cellLongPress:(UITapGestureRecognizer *)tap {
    //    deleteImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pop_deleted_default_handle_course"]];
    //    [deleteImage setUserInteractionEnabled:YES];
    //    [self.contentView addSubview:deleteImage];
    //
    //    [deleteImage mas_makeConstraints:^(MASConstraintMaker *make) {
    //        make.top.right.equalTo(self.contentView);
    //    }];
    //
    //    UITapGestureRecognizer *tapCilk = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(deleteStudent:)];
    //    [deleteImage addGestureRecognizer:tapCilk];
    
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"是否删除选中的学生" preferredStyle:(UIAlertControllerStyleActionSheet)];
    UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
        
        self.ClickDelete ? self.ClickDelete(self.Model.ID,self.Model.O_UID) : nil;
    }];
    
    UIAlertAction *actionTwo = [UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleCancel) handler:^(UIAlertAction * _Nonnull action) {
        
        //        if (_ReloadData) {
        //            _ReloadData();
        //            [deleteImage removeFromSuperview];
        //        }
    }];
    
    [alertVC addAction:actionOne];
    [alertVC addAction:actionTwo];
    
    [[[AppDelegate shareAppDelegate] getCurrentUIVC] presentViewController:alertVC animated:YES completion:nil];
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    _Img.layer.cornerRadius = _Img.frame.size.width / 2;
    _Img.layer.masksToBounds = YES;
}
@end
